package io.renren.modules.emp.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.emp.entity.EmpEntity;
import io.renren.modules.emp.service.EmpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 员工表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-04-07 18:14:57
 */
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        //PageUtils page = empService.queryPage(params);
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize =  Integer.parseInt(String.valueOf(params.get("limit")));
        String ename = String.valueOf(params.get("key"));
        Page<EmpEntity> page = new Page<>(pageIndex,pageSize);
        empService.queryPageByCondition(ename,page);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{empno}")
    public R info(@PathVariable("empno") Integer empno){
		EmpEntity emp = empService.getById(empno);

        return R.ok().put("emp", emp);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:emp:save")
    public R save(@RequestBody EmpEntity emp){
		empService.save(emp);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody EmpEntity emp){
		empService.updateById(emp);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] empnos){
		empService.removeByIds(Arrays.asList(empnos));

        return R.ok();
    }

}
